<%-- 
    Document   : resultados
    Created on : 25/11/2009, 06:06:03 PM
    Author     : Juan Garza
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="Model.JConexion"%>
<%@page import="java.util.ArrayList" %>
<%@page import="java.util.Iterator" %>
<%@page import="javax.servlet.http.HttpServlet" %>
<%@page import="javax.servlet.http.HttpServletRequest" %>
<%@page import="javax.servlet.http.HttpServletResponse" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Resultados</title>
    </head>
    <body>
        <form action="apuestas.jsp" method="post">
            <%
                String query="";
                String[] dat;
                ArrayList al = new ArrayList();
                JConexion jc = new JConexion("");
                Iterator it = null;
                int win=0;
                int place=0;
                int show=0;

                query = "SELECT r.peso, r.posicion_salida, ca.nombre FROM rel_carrera_caballo r, cat_carrera c, cat_caballo ca where c.id_carrera = r.fk_id_carrera and ca.id_caballo = r.fk_id_caballo;";
                al.clear();
                al = jc.MySQLArray("MySQLRM", "Consulta", query);
                it = al.iterator();
                int pos = 0;
                dat = (String[]) al.get(pos);
            %>
                <br>
                <br>
                <table align="center">
                    <tr>
                        <th colspan="4" align="center" > R E S U L T A D O S  </th>
                    </tr>
                    <tr>
                        <th width="120">Caballo </th><th width="90" align="center">W I N</th><th width="90" align="center">P L A C E</th><th width="90" align="center">S H O W</th>
                    </tr>
                    <% while(it.hasNext()){
                         dat = (String[]) al.get(pos); %>
                        <% if (pos == 0) { %>
                             <tr>
                             <td align="center"><% out.println(dat[2].toString()); %></td><td align="center"><% out.println(dat[0].toString()); %></td><td align="center"><% out.println(dat[0].toString()); %></td><td align="center"><% out.println(dat[0].toString()); %></td>
                              </tr>
                             <% }
                            else
                                if (pos == 1)  { %>
                                   <tr>
                                   <td align="center"><% out.println(dat[2].toString()); %> </td><td align="center"> </td><td align="center"><% out.println(dat[0].toString()); %></td><td align="center"><% out.println(dat[0].toString()); %></td>
                                   </tr>
                              <% } else %>
                                <tr>
                                <td align="center"><% out.println(dat[2].toString()); %> </td><td align="center"> </td><td align="center">></td><td align="center"><% out.println(dat[0].toString()); %></td>
                                </tr>


                <%
                        win = win + Integer.parseInt(dat[0].toString());
                        place = place + Integer.parseInt(dat[0].toString());
                        show = show + Integer.parseInt(dat[0].toString());
                        it.next();
                        pos++;
                        }
                %>
                <td align="center"><% out.println("SUMA"); %></td><td align="center"><% out.println(win); %></td><td align="center"><% out.println(place); %></td><td align="center"><% out.println(show); %></td>
                </table>
                <hr>
                <center>
                <table>
                <tr>
                <td align="left" width="180">
                <a href="<% out.println("http://" + request.getLocalName()+ ":" + request.getLocalPort() + "/RoyalMowes/login.jsp"); %>">Nueva Apuesta</a>
                </td><td align="rigth" weidth="180">
                <a href="<% out.println("http://" + request.getLocalName()+ ":" + request.getLocalPort() + "/RoyalMowes/login.jsp"); %>">Carrera</a>
                </td>
                </tr>
                </table>
                </center>
        </form>
    </body>
</html>
